<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('定时任务管理')"/>
</head>

<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="jobForm" class="form-inline" th:action="@{/sys/schedule/list}">
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3">
                            <label>方法名称：</label>
                            <input type="text" id="methodName" name="methodName"/>
                        </li>
                        <li>
                            <button id="jobSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置</button>
                            <button id="jobAdvancedSearch" type="button" class="btn btn-primary btn-rounded btn-sm" style="display: none"><i class="fa fa-caret-down"></i>&nbsp;高级搜索</button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-info">
            <div class="btn-group hidden-xs toolbar" id="jobToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" onclick="add()" shiro:hasPermission="sys:schedule:save">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="edit()" shiro:hasPermission="sys:schedule:update">
                    <i class="fa fa-edit"></i> 编辑
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="del()" shiro:hasPermission="sys:schedule:delete">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="pause()" shiro:hasPermission="sys:schedule:resume">
                    <i class="fa fa-stop"></i> 暂停
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="resume()" shiro:hasPermission="sys:schedule:resume">
                    <i class="fa fa-pause"></i> 恢复
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="run()" shiro:hasPermission="sys:schedule:run">
                    <i class="fa fa-play"></i> 立即运行
                </a>
            </div>
            <table id="job">
            </table>
        </div>
    </div>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Page-Level Scripts -->
<script th:inline="javascript">

    var searcher = Searcher.createBS('#job',
        [
            {checkbox: true},
            {title: 'jobId',field:"jobId", visible: false,},
            {title: "bean名称", field:"beanName", align: 'center', valign: 'middle'},
            {title: "方法名",field:"methodName",  align: 'center', valign: 'middle'},
            {title: "参数",field:"params",  align: 'center', valign: 'middle'},
            {title: "cron表达式",field:"cronExpression",  align: 'center', valign: 'middle'},
            {title: "备注",field:"remark",  align: 'center', valign: 'middle'},
            {title: "状态",field:"status",  align: 'center', valign: 'middle',
                formatter:Formatter.showDesc({1:'正常', 2:'暂停'}, '-')
            }
        ]
    )


    /**
     * 跳转至新增页
     */
    function add() {
        var index=Dialog.openUrl("新增", ctxPath + '/modules//sys/job/schedule_job_info.html',
            {
                area : ['800px','550px'],
                maxmin: true
            }
        );
    }

    /**
     * 编辑
     */
    function edit() {
        var rowDatas = searcher.getSelectedRows("jobId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行");
            return;
        }
        var index = Dialog.openUrl("编辑", ctxPath + '/modules/sys/job/schedule_job_info.html/'+rowDatas,
            { area : ['800px','550px']
            });
    }

    function del(){
        var rowDatas = searcher.getSelectedRows("jobId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定删除？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/schedule/delete", {jobIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    formSearch();
                });
            });
        });
    }

    function pause(){
        var rowDatas = searcher.getSelectedRows("jobId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定暂停？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/schedule/pause", {jobIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    formSearch();
                });
            });
        });
    }

    function resume(){
        var rowDatas = searcher.getSelectedRows("jobId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定恢复？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/schedule/resume", {jobIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    formSearch();
                });
            });
        });
    }

    function run(){
        var rowDatas = searcher.getSelectedRows("jobId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定执行？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/schedule/run", {jobIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    formSearch();
                });
            });
        });
    }

    function formSearch() {
        searcher.refresh();
    }
</script>
</body>